# 给定一个罗马数字，将其转换成整数。

# IV = 5  I < V -> res - I + V
# 思路: 数组左边的数比右边的数字小, 则结果减去当前数字,反之加上当前数字

class Solution(object):

    def romanToInt(self, s):
        """
        :type s: str
        :rtype: int
        """
        # 罗马字符字典
        convert = {
            "I": 1,
            "V": 5, 
            "X": 10,
            "L": 50,
            "C": 100,
            "D": 500,
            "M": 1000
        }
        res = 0
        for i in range(len(s)):
            if i < len(s)-1 and convert[s[i]] < convert[s[i+1]]:
                res = res - convert[s[i]]
            else:
                res = res + convert[s[i]]
        return res




